package com.itqf.controller;

import com.google.gson.Gson;
import com.itqf.entity.Type;
import com.itqf.service.TypeService;
import com.itqf.service.impl.TypeServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;


@WebServlet(name = "TypeController" , value = "/type")
public class TypeController extends BaseServlet {

    //初始化业务逻辑对象
    private TypeService typeService = new TypeServiceImpl();

    public String findAll(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        //1.调用业务逻辑进行分页查询商品信息
        List<Type> all = typeService.findAll();

        //2.将集合转换为json数据
        //2.1创建Gson对象
        Gson gson = new Gson();
        //2.2将集合转换为字符串
        String json = gson.toJson(all);
        //3.响应（返回json字符串数据）
        return json;
    }
}
